package com.eckey.lab.consumer.service.impl;

import com.alibaba.fastjson.JSON;
import com.eckey.lab.common.Result;
import com.eckey.lab.consumer.bean.UserVO;
import com.eckey.lab.consumer.service.DubboConsumerService;
import com.eckey.lab.interfaces.UserProviderAPI;
import com.eckey.lab.interfaces.bean.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * @Author: ChengLiang
 * @CreateTime: 2023-11-13  10:56
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Service
public class DubboConsumerServiceImpl implements DubboConsumerService {

    @Reference(interfaceClass = UserProviderAPI.class, version = "1.0.0")
    private UserProviderAPI userProviderAPI;

    @Override
    public Result insert(UserVO userVO) {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserName(userVO.getUserName());
        userDTO.setNickName(userVO.getNickName());
        userDTO.setAge(userVO.getAge());
        userDTO.setGender(userVO.getGender());
        userDTO.setCreateTime(userVO.getCreateTime());
        userDTO.setModifyTime(userVO.getModifyTime());
        log.info("userDTO:{}", JSON.toJSONString(userDTO));
        return userProviderAPI.insert(userDTO);
    }

    @Override
    public Result<UserDTO> selectByKeyId(Integer id) {
        Result<UserDTO> userDTOResult = userProviderAPI.queryById(id);
        log.info("查询结果为;{}", JSON.toJSONString(userDTOResult.getData()));
        return userDTOResult;
    }
}
